package com.database;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class LoginDb {
	private DataBaseConnection dataBaseConnection=null;
	private Connection connection=null;
	private Statement statement=null;
public LoginDb() {
	try
	{
		dataBaseConnection = new DataBaseConnection();
		connection = dataBaseConnection.CallConnection();
		statement = connection.createStatement();	
	}
	catch (Exception e) {
		e.printStackTrace();
	}
	
}
public String LoginDatabase(String CustomerName,String PassWord)
{
	String result="";
	try
	{
		boolean status=true;
		boolean success=true;
		
		ResultSet resultSet=statement.executeQuery("select * from ACCOUNT where CustomerName='"+CustomerName+"'");
		while(resultSet.next())
		{
			if(resultSet.getString("PASSWORD").equalsIgnoreCase(PassWord))
			{
				success=false;
				result=resultSet.getString("ACCOUNTNUMBER");
				break;
			}
			else
			{
				status=false;
			}
		}
		if(!status)
		{
			result="Invalid Password";
		}
		else if(status&success)
		{
			result="Invalid UserName";
		}
		else
		{
			result+=" success";
		}
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	return result;
}
}
